#/bin/bash

# arg 1:  the new package version
post_install() {
  getent group backuppc >/dev/null || groupadd -g 126 backuppc
  getent passwd backuppc >/dev/null || useradd -d /var/lib/backuppc -u 126 -g 126 backuppc
  systemd-tmpfiles --create backuppc.conf
  true
}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
  # change uid of old version
  if (( $(vercmp $2 3.2.1-8) < 0 )); then
    if pgrep -u backuppc >/dev/null; then
      echo '==> backuppc user is running.'
      echo '==> You must manually change uid and gid of backuppc!'
      echo '==> e.g: usermod -u 126 -g 126 backuppc'
    else
      usermod -u 126 -g 126 backuppc
      echo '==> backuppc uid/gid have changed. Check your filesystem permissions.'
    fi
  fi
  # ensure /run/backuppc exists
  systemd-tmpfiles --create backuppc.conf
  true
}

# arg 1:  the old package version
post_remove() {
  userdel -f backuppc &>/dev/null
  groupdel backuppc &>/dev/null
  true
}

# vim:set ts=2 sw=2 ft=sh et:
